<template>
  <div>
    <!-- 第一行 4 个 card -->
    <el-row :gutter="20">
      <!-- 骨架 -->
      <template v-if="panels.length === 0">
        <el-col :span="6" v-for="i in 4" :key="i">
          <el-skeleton style="width: 100%" animated loading>
            <template #template>
              <el-card shadow="hover" class="border-0">
                <template #header>
                  <div class="flex justify-between">
                    <el-skeleton-item variant="text" style="width: 50%" />
                    <el-skeleton-item variant="text" style="width: 10%" />
                  </div>
                </template>
                <el-skeleton-item variant="h3" style="width: 80%" />
                <el-divider />
                <div class="flex justify-between text-sm text-gray-500">
                  <el-skeleton-item variant="text" style="width: 50%" />
                  <el-skeleton-item variant="text" style="width: 10%" />
                </div>
              </el-card>
            </template>
          </el-skeleton>
        </el-col>
      </template>

      <!-- 实体卡片 -->
      <template v-else>
        <el-col
          :span="6"
          :offset="0"
          v-for="(item, index) in panels"
          :key="index"
        >
          <el-card shadow="hover" class="border-0">
            <template #header>
              <div class="flex justify-between">
                <span>{{ item.title }}</span>
                <el-tag :type="item.unitColor" effect="plain">{{
                  item.unit
                }}</el-tag>
              </div>
            </template>
            <span class="text-3xl font-bold text-gray-500">
              <count-to :value="item.value" />
            </span>
            <el-divider />
            <div class="flex justify-between text-sm text-gray-500">
              <span>{{ item.subTitle }}</span>
              <span>{{ item.subValue }}</span>
            </div>
          </el-card>
        </el-col>
      </template>
    </el-row>

    <!-- 第二行 8 个 card -->
    <el-row>
      <el-col :span="24">
        <index-navs></index-navs>
      </el-col>
    </el-row>

    <el-row :gutter="20" class="mt-5">
      <el-col :span="12" :offset="0">
        <index-charts v-permission="['goods/list GET']"></index-charts>
      </el-col>
      <el-col :span="12">
        <index-card
          title="店铺及商品提示"
          tip="店铺及商品提示"
          :btns="goods"
          class="mb-3"
        ></index-card>
        <index-card
          title="交易提示"
          tip="需要立即处理"
          :btns="order"
        ></index-card>
      </el-col>
    </el-row>
  </div>
</template>
<script setup>
import { ref } from "vue";
import { getStatistics } from "~/api";
import CountTo from "~/components/CountTo.vue";
import IndexNavs from "~/components/IndexNavs.vue";
import IndexCharts from "~/components/IndexCharts.vue";
import IndexCard from "~/components/IndexCard.vue";
import { getStatistics301 } from "~/api";

const panels = ref([]);
const goods = ref([]);
const order = ref([]);

getStatistics().then((res) => {
  panels.value = res;
});

// 第三排（右下角）右边 card 数据源
getStatistics301()
  .then((res) => {
    goods.value = res.goods;
    order.value = res.order;
  })
  .catch((err) => console.log(err));
</script>
